﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Data;
using System.Drawing.Imaging;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text.RegularExpressions;
using System.Collections;

namespace MSL.Utility.Images
{
    /// <summary>
    /// 图表类
    /// </summary>
    public class Chart
    {
        #region 饼图
        /*
         调用方法如：
         * MemoryStream stream = new MemoryStream();
            MemoryStream columnarStream = new MemoryStream();
            Bitmap graph = null;
            data dt = new data();
            dt.Columns.Add("Ven", typeof(System.String));
            dt.Columns.Add("BadQty", typeof(System.Int32));
            dt.Rows.Add("山东威海", 65);
            dt.Rows.Add("安徽黄山", 23);
            dt.Rows.Add("江苏太湖", 34);
            dt.Rows.Add("陕西华山", 98);
            dt.Rows.Add("湖南景刚山", 102);
            dt.Rows.Add("海南南海", 74);
            graph = Utility.ChartHelper.GetPieGraph("Compex各组别不合格率统计", 600, 500, 100, 30, dt);
            graph.Save(stream, ImageFormat.Jpeg);
            //图片输出
            Response.Clear();
            Response.ContentType = "image/jpeg";
            Response.BinaryWrite(stream.ToArray());
         */
        /// <summary>
        /// 
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="width">宽</param>
        /// <param name="height">高</param>
        /// <param name="left"></param>
        /// <param name="top"></param>
        /// <param name="gdt">data对象</param>
        /// <returns>Bitmap对象</returns>
        public static Bitmap GetPieGraph(string title, int width, int height, int left, int top, DataTable gdt)
        {
            Bitmap objbitmap = new Bitmap(width, height);
            Graphics objgraphics;
            objgraphics = Graphics.FromImage(objbitmap);
            objgraphics.Clear(Color.White);
            StringFormat drawformat = new System.Drawing.StringFormat(StringFormatFlags.DirectionVertical);
            StringFormat drawformat1 = new System.Drawing.StringFormat(StringFormatFlags.DisplayFormatControl);
            objgraphics.DrawString(title, new Font("宋体", 16), Brushes.Black, 150, 5, drawformat1);
            PointF symbolleg = new PointF(left, height - top - 45);
            PointF descleg = new PointF(left + 20, height - top - 45);
            //画边框
            objgraphics.DrawRectangle(Pens.Black, 0, 0, width - 1, height - 1);
            //画内小框
            int h = gdt.Rows.Count / 4;
            if (gdt.Rows.Count % 4 > 0)
            {
                h = h + 1;
            }
            objgraphics.DrawRectangle(Pens.Black, left - 10, height - top - 50, gdt.Rows.Count * 70 + 10, 20 * h);
            //显示什么颜色代表什么的 
            for (int i = 0; i < gdt.Rows.Count; i++)
            {
                if (i >= 4 && (i + 1) % 4 == 1)
                {
                    symbolleg.Y += 20;
                    descleg.Y += 20;
                    symbolleg.X = left;
                    descleg.X = left + 20;
                }
                objgraphics.FillRectangle(new SolidBrush(getcolor(i)), symbolleg.X, symbolleg.Y, 12, 10);
                objgraphics.DrawRectangle(Pens.Black, symbolleg.X, symbolleg.Y, 12, 10);
                objgraphics.DrawString(gdt.Rows[i][0].ToString().Trim(), new Font("宋体", 10), Brushes.Black, descleg);
                symbolleg.X += 100;
                descleg.X += 100;
            }
            float sglcurrentangle = 0;
            float sgltotalangle = 0;
            float sgltotalvalues = 0;
            for (int i = 0; i < gdt.Rows.Count; i++)
            {
                sgltotalvalues += float.Parse(gdt.Rows[i][1].ToString().Trim());
            }
            for (int i = 0; i < gdt.Rows.Count; i++)
            {
                sglcurrentangle = float.Parse(gdt.Rows[i][1].ToString().Trim()) / sgltotalvalues * 360;
                objgraphics.FillPie(new SolidBrush(getcolor(i)), left + 50, top + 30, 300, 300, sgltotalangle, sglcurrentangle);
                objgraphics.DrawPie(Pens.Black, left + 50, top + 30, 300, 300, sgltotalangle, sglcurrentangle);
                //半径 r
                double r = 300 / 2;
                //圆心位置：
                double cX = left + 50 + r;
                double cY = top + 30 + r;
                //圆上点的坐标：
                double dX = r * Math.Cos((360 - sgltotalangle - sglcurrentangle / 2) * 3.14 / 180);
                double dY = r * Math.Sin((360 - sgltotalangle - sglcurrentangle / 2) * 3.14 / 180);
                //圆上位置:
                double dcX = cX + dX;
                double dcY = cY - dY;
                //半径 r
                double r1 = 350 / 2;
                //圆心位置：
                double cX1 = left + 50 + r;
                double cY1 = top + 30 + r;
                //圆上点的坐标：
                double dX1 = r1 * Math.Cos((360 - sgltotalangle - sglcurrentangle / 2) * 3.14 / 180);
                double dY1 = r1 * Math.Sin((360 - sgltotalangle - sglcurrentangle / 2) * 3.14 / 180);
                //圆上位置:
                double dcX1 = cX1 + dX1;
                double dcY1 = cY1 - dY1;

                objgraphics.DrawLine(Pens.Black, System.Convert.ToInt32(dcX), System.Convert.ToInt32(dcY), System.Convert.ToInt32(dcX1), System.Convert.ToInt32(dcY1));
                if (dX1 >= 0 && dY1 >= 0)
                {
                    objgraphics.DrawString(gdt.Rows[i][0].ToString().Trim(), new Font("宋体", 10), Brushes.Black, System.Convert.ToInt32(dcX1), System.Convert.ToInt32(dcY1 - 5));
                }
                if (dX1 <= 0 && dY1 >= 0)
                {
                    objgraphics.DrawString(gdt.Rows[i][0].ToString().Trim(), new Font("宋体", 10), Brushes.Black, System.Convert.ToInt32(dcX1 - 25), System.Convert.ToInt32(dcY1 - 15));
                }
                if (dX1 <= 0 && dY1 <= 0)
                {
                    objgraphics.DrawString(gdt.Rows[i][0].ToString().Trim(), new Font("宋体", 10), Brushes.Black, System.Convert.ToInt32(dcX1 - 30), System.Convert.ToInt32(dcY1));
                }
                if (dX1 >= 0 && dY1 <= 0)
                {
                    objgraphics.DrawString(gdt.Rows[i][0].ToString().Trim(), new Font("宋体", 10), Brushes.Black, System.Convert.ToInt32(dcX1), System.Convert.ToInt32(dcY1));
                }
                //GetLet(left + 50+150, top + 30+150,300,sgltotalangle, sglcurrentangle,arrvalues[i].ToString());
                sgltotalangle += sglcurrentangle;
            }
            return objbitmap;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="startX"></param>
        /// <param name="startY"></param>
        /// <param name="dia"></param>
        /// <param name="totalAngle"></param>
        /// <param name="currentAngle"></param>
        /// <param name="leg"></param>
        public static void GetLet(int startX, int startY, double dia, double totalAngle, double currentAngle, string leg)
        {
            double x = 0;
            double y = 0;
            double r = dia / 2;
            x = r * Math.Cos((360 - totalAngle - currentAngle / 2) * 3.14 / 180);
            y = r * Math.Sin((360 - totalAngle - currentAngle / 2) * 3.14 / 180);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="itemindex"></param>
        /// <returns></returns>
        public static Color getcolor(int itemindex)
        {
            Color objcolor;
            if (itemindex >= 14)
            {
                itemindex = itemindex % 14;
            }
            if (itemindex == 0)
            {
                objcolor = Color.DarkMagenta;
            }
            else if (itemindex == 1)
            {
                objcolor = Color.MediumAquamarine;
            }
            else if (itemindex == 2)
            {
                objcolor = Color.DeepSkyBlue;
            }
            else if (itemindex == 3)
            {
                objcolor = Color.DarkRed;
            }
            else if (itemindex == 4)
            {
                objcolor = Color.Pink;
            }
            else if (itemindex == 5)
            {
                objcolor = Color.Salmon;
            }
            else if (itemindex == 6)
            {
                objcolor = Color.Khaki;
            }
            else if (itemindex == 7)
            {
                objcolor = Color.Maroon;
            }
            else if (itemindex == 8)
            {
                objcolor = Color.LawnGreen;
            }
            else if (itemindex == 9)
            {
                objcolor = Color.LightGoldenrodYellow;
            }
            else if (itemindex == 10)
            {
                objcolor = Color.Moccasin;
            }
            else if (itemindex == 11)
            {
                objcolor = Color.YellowGreen;
            }
            else if (itemindex == 12)
            {
                objcolor = Color.DarkCyan;
            }
            else if (itemindex == 13)
            {
                objcolor = Color.SteelBlue;
            }
            else if (itemindex == 14)
            {
                objcolor = Color.Tomato;
            }
            else
            {
                objcolor = Color.SlateGray;
            }
            return objcolor;
        }
        #endregion
    }
    /// <summary>
    /// 曲线图类
    /// </summary>
    public class Curve2D
    {
        /*
         调用方法如：
         *  Utility.Curve2D cuv2D = new Utility.Curve2D();
            cuv2D.Width = 1000;
            cuv2D.Height = 600;
            cuv2D.Title = "测试数据";
            cuv2D.CurveColors = new Color[] { Color.Red, Color.Blue, Color.Yellow, Color.Black }; //曲线颜色
            cuv2D.Keys = new string[] { "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月" }; //键
            cuv2D.Values = new float[] {20.0f, 30.0f, 50.0f, 55.4f, 21.6f, 12.8f, 99.5f, 36.4f, 78.2f, 56.4f, 45.8f, 66.5f,
                                                    59.5f, 36.4f, 78.2f, 56.4f, 45.8f, 66.5f, 20.0f, 30.0f, 50.0f, 55.4f, 21.6f, 32.8f, 
                                                    92.5f, 36.4f, 88.2f, 56.4f, 35.8f, 76.5f, 20.0f, 30.0f, 60.0f, 55.4f, 21.6f, 52.8f,
                                                   30.0f, 30.0f, 50.0f, 55.4f, 21.6f, 12.8f, 99.5f, 36.4f, 78.2f, 56.4f, 45.8f, 46.5f}; //值


            cuv2D.Fit();
            var imagetemp = cuv2D.CreateImage();
            string imagepath = "E:/a.Bmp";
            imagetemp.Save(imagepath, System.Drawing.Imaging.ImageFormat.Bmp);
         */
        #region 私有字段
        private Graphics objGraphics; //Graphics 类提供将对象绘制到显示设备的方法
        private Bitmap objBitmap; //位图对象
        private float fltWidth = 480; //图像宽度
        private float fltHeight = 248; //图像高度
        private float fltXSlice = 50; //X轴刻度宽度
        private float fltYSlice = 50; //Y轴刻度宽度
        private float fltYSliceValue = 20; //Y轴刻度的数值宽度
        private float fltYSliceBegin = 0; //Y轴刻度开始值
        private float fltTension = 0.5f;
        private String strTitle = "曲线图"; //标题
        private String strXAxisText = "月份"; //X轴说明文字
        private String strYAxisText = "万元"; //Y轴说明文字
        private String[] strsKeys = new string[] { "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月" }; //键
        private float[] fltsValues = new float[] { 20.0f, 30.0f, 50.0f, 55.4f, 21.6f, 12.8f, 99.5f, 36.4f, 78.2f, 56.4f, 45.8f, 66.5f, 99.5f, 36.4f, 78.2f, 56.4f, 45.8f, 66.5f, 20.0f, 30.0f, 50.0f, 55.4f, 21.6f, 12.8f }; //值
        private Color clrBgColor = Color.Snow; //背景色
        private Color clrTextColor = Color.Black; //文字颜色
        private Color clrBorderColor = Color.Black; //整体边框颜色
        private Color clrAxisColor = Color.Black; //轴线颜色
        private Color clrAxisTextColor = Color.Black; //轴说明文字颜色
        private Color clrSliceTextColor = Color.Black; //刻度文字颜色
        private Color clrSliceColor = Color.Black; //刻度颜色
        private Color[] clrsCurveColors = new Color[] { Color.Red, Color.Blue }; //曲线颜色
        private float fltXSpace = 100f; //图像左右距离边缘距离
        private float fltYSpace = 100f; //图像上下距离边缘距离
        private Int32 intFontSize = 9; //字体大小号数
        private float fltXRotateAngle = 30f; //X轴文字旋转角度
        private float fltYRotateAngle = 0f; //Y轴文字旋转角度
        private Int32 intCurveSize = 2; //曲线线条大小
        private Int32 intFontSpace = 0; //intFontSpace 是字体大小和距离调整出来的一个比较适合的数字
        #endregion

        #region 公共属性
        /// <summary>
        /// 图像的宽度
        /// </summary>
        public float Width
        {
            set
            {
                if (value < 100)
                {
                    fltWidth = 100;
                }
                else
                {
                    fltWidth = value;
                }
            }
            get
            {
                if (fltWidth <= 100)
                {
                    return 100;
                }
                else
                {
                    return fltWidth;
                }
            }
        }
        /// <summary>
        /// 图像的高度
        /// </summary>
        public float Height
        {
            set
            {
                if (value < 100)
                {
                    fltHeight = 100;
                }
                else
                {
                    fltHeight = value;
                }
            }
            get
            {
                if (fltHeight <= 100)
                {
                    return 100;
                }
                else
                {
                    return fltHeight;
                }
            }
        }
        /// <summary>
        /// X轴刻度宽度
        /// </summary>
        public float XSlice
        {
            set { fltXSlice = value; }
            get { return fltXSlice; }
        }
        /// <summary>
        /// Y轴刻度宽度
        /// </summary>
        public float YSlice
        {
            set { fltYSlice = value; }
            get { return fltYSlice; }
        }
        /// <summary>
        /// Y轴刻度的数值宽度
        /// </summary>
        public float YSliceValue
        {
            set { fltYSliceValue = value; }
            get { return fltYSliceValue; }
        }
        /// <summary>
        /// Y轴刻度开始值
        /// </summary>
        public float YSliceBegin
        {
            set { fltYSliceBegin = value; }
            get { return fltYSliceBegin; }
        }
        /// <summary>
        /// 张力系数
        /// </summary>
        public float Tension
        {
            set
            {
                if (value < 0.0f && value > 1.0f)
                {
                    fltTension = 0.5f;
                }
                else
                {
                    fltTension = value;
                }
            }
            get
            {
                return fltTension;
            }
        }
        /// <summary>
        /// 标题
        /// </summary>
        public string Title
        {
            set { strTitle = value; }
            get { return strTitle; }
        }
        /// <summary>
        /// 键，X轴数据
        /// </summary>
        public string[] Keys
        {
            set { strsKeys = value; }
            get { return strsKeys; }
        }
        /// <summary>
        /// 值，Y轴数据
        /// </summary>
        public float[] Values
        {
            set { fltsValues = value; }
            get { return fltsValues; }
        }
        /// <summary>
        /// 背景色
        /// </summary>
        public Color BgColor
        {
            set { clrBgColor = value; }
            get { return clrBgColor; }
        }
        /// <summary>
        /// 文字颜色
        /// </summary>
        public Color TextColor
        {
            set { clrTextColor = value; }
            get { return clrTextColor; }
        }
        /// <summary>
        /// 整体边框颜色
        /// </summary>
        public Color BorderColor
        {
            set { clrBorderColor = value; }
            get { return clrBorderColor; }
        }
        /// <summary>
        /// 轴线颜色
        /// </summary>
        public Color AxisColor
        {
            set { clrAxisColor = value; }
            get { return clrAxisColor; }
        }
        /// <summary>
        /// X轴说明文字
        /// </summary>
        public string XAxisText
        {
            set { strXAxisText = value; }
            get { return strXAxisText; }
        }
        /// <summary>
        /// Y轴说明文字
        /// </summary>
        public string YAxisText
        {
            set { strYAxisText = value; }
            get { return strYAxisText; }
        }
        /// <summary>
        /// 轴说明文字颜色
        /// </summary>
        public Color AxisTextColor
        {
            set { clrAxisTextColor = value; }
            get { return clrAxisTextColor; }
        }
        /// <summary>
        /// 刻度文字颜色
        /// </summary>
        public Color SliceTextColor
        {
            set { clrSliceTextColor = value; }
            get { return clrSliceTextColor; }
        }
        /// <summary>
        /// 刻度颜色
        /// </summary>
        public Color SliceColor
        {
            set { clrSliceColor = value; }
            get { return clrSliceColor; }
        }
        /// <summary>
        /// 曲线颜色
        /// </summary>
        public Color[] CurveColors
        {
            set { clrsCurveColors = value; }
            get { return clrsCurveColors; }
        }
        /// <summary>
        /// X轴文字旋转角度
        /// </summary>
        public float XRotateAngle
        {
            get { return fltXRotateAngle; }
            set { fltXRotateAngle = value; }
        }
        /// <summary>
        /// Y轴文字旋转角度
        /// </summary>
        public float YRotateAngle
        {
            get { return fltYRotateAngle; }
            set { fltYRotateAngle = value; }
        }
        /// <summary>
        /// 图像左右距离边缘距离
        /// </summary>
        public float XSpace
        {
            get { return fltXSpace; }
            set { fltXSpace = value; }
        }
        /// <summary>
        /// 图像上下距离边缘距离
        /// </summary>
        public float YSpace
        {
            get { return fltYSpace; }
            set { fltYSpace = value; }
        }
        /// <summary>
        /// 字体大小号数
        /// </summary>
        public Int32 FontSize
        {
            get { return intFontSize; }
            set { intFontSize = value; }
        }
        /// <summary>
        /// 曲线线条大小
        /// </summary>
        public Int32 CurveSize
        {
            get { return intCurveSize; }
            set { intCurveSize = value; }
        }
        #endregion

        /// <summary>
        /// 自动根据参数调整图像大小
        /// </summary>
        public void Fit()
        {
            //计算字体距离
            intFontSpace = FontSize + 5;
            //计算图像边距
            float fltSpace = Math.Min(Width / 6, Height / 6);
            XSpace = fltSpace;
            YSpace = fltSpace;
            //计算X轴刻度宽度
            XSlice = (Width - 2 * XSpace) / (Keys.Length - 1);
            //计算Y轴刻度宽度和Y轴刻度开始值
            float fltMinValue = 0;
            float fltMaxValue = 0;
            for (int i = 0; i < Values.Length; i++)
            {
                if (Values[i] < fltMinValue)
                {
                    fltMinValue = Values[i];
                }
                else if (Values[i] > fltMaxValue)
                {
                    fltMaxValue = Values[i];
                }
            }
            if (YSliceBegin > fltMinValue)
            {
                YSliceBegin = fltMinValue;
            }
            int intYSliceCount = (int)(fltMaxValue / YSliceValue);
            if (fltMaxValue % YSliceValue != 0)
            {
                intYSliceCount++;
            }
            YSlice = (Height - 2 * YSpace) / intYSliceCount;
        }
        /// <summary>
        /// 生成图像并返回bmp图像对象
        /// </summary>
        /// <returns></returns>
        public Bitmap CreateImage()
        {
            InitializeGraph();
            int intKeysCount = Keys.Length;
            int intValuesCount = Values.Length;
            if (intValuesCount % intKeysCount == 0)
            {
                int intCurvesCount = intValuesCount / intKeysCount;
                for (int i = 0; i < intCurvesCount; i++)
                {
                    float[] fltCurrentValues = new float[intKeysCount];
                    for (int j = 0; j < intKeysCount; j++)
                    {
                        fltCurrentValues[j] = Values[i * intKeysCount + j];
                    }
                    DrawContent(ref objGraphics, fltCurrentValues, clrsCurveColors[i]);
                }
            }
            else
            {
                objGraphics.DrawString("发生错误，Values的长度必须是Keys的整数倍!", new Font("宋体", FontSize + 5), new SolidBrush(TextColor), new Point((int)XSpace, (int)(Height / 2)));
            }
            return objBitmap;
        }
        /// <summary>
        /// 初始化和填充图像区域，画出边框，初始标题
        /// </summary>
        private void InitializeGraph()
        {
            //根据给定的高度和宽度创建一个位图图像
            objBitmap = new Bitmap((int)Width, (int)Height);
            //从指定的 objBitmap 对象创建 objGraphics 对象 (即在objBitmap对象中画图)
            objGraphics = Graphics.FromImage(objBitmap);
            //根据给定颜色(LightGray)填充图像的矩形区域 (背景)
            objGraphics.DrawRectangle(new Pen(BorderColor, 1), 0, 0, Width - 1, Height - 1); //画边框
            objGraphics.FillRectangle(new SolidBrush(BgColor), 1, 1, Width - 2, Height - 2); //填充边框
            //画X轴,注意图像的原始X轴和Y轴计算是以左上角为原点，向右和向下计算的
            float fltX1 = XSpace;
            float fltY1 = Height - YSpace;
            float fltX2 = Width - XSpace + XSlice / 2;
            float fltY2 = fltY1;
            objGraphics.DrawLine(new Pen(new SolidBrush(AxisColor), 1), fltX1, fltY1, fltX2, fltY2);
            //画Y轴
            fltX1 = XSpace;
            fltY1 = Height - YSpace;
            fltX2 = XSpace;
            fltY2 = YSpace - YSlice / 2;
            objGraphics.DrawLine(new Pen(new SolidBrush(AxisColor), 1), fltX1, fltY1, fltX2, fltY2);
            //初始化轴线说明文字
            SetAxisText(ref objGraphics);
            //初始化X轴上的刻度和文字
            SetXAxis(ref objGraphics);
            //初始化Y轴上的刻度和文字
            SetYAxis(ref objGraphics);
            //初始化标题
            CreateTitle(ref objGraphics);
        }
        /// <summary>
        /// 初始化轴线说明文字
        /// </summary>
        /// <param name="objGraphics"></param>
        private void SetAxisText(ref Graphics objGraphics)
        {
            float fltX = Width - XSpace + XSlice / 2 - (XAxisText.Length - 1) * intFontSpace;
            float fltY = Height - YSpace - intFontSpace;
            objGraphics.DrawString(XAxisText, new Font("宋体", FontSize), new SolidBrush(AxisTextColor), fltX, fltY);
            fltX = XSpace + 5;
            fltY = YSpace - YSlice / 2 - intFontSpace;
            for (int i = 0; i < YAxisText.Length; i++)
            {
                objGraphics.DrawString(YAxisText[i].ToString(), new Font("宋体", FontSize), new SolidBrush(AxisTextColor), fltX, fltY);
                fltY += intFontSpace; //字体上下距离
            }
        }
        /// <summary>
        /// 初始化X轴上的刻度和文字
        /// </summary>
        /// <param name="objGraphics"></param>
        private void SetXAxis(ref Graphics objGraphics)
        {
            float fltX1 = XSpace;
            float fltY1 = Height - YSpace;
            float fltX2 = XSpace;
            float fltY2 = Height - YSpace;
            int iCount = 0;
            int iSliceCount = 1;
            float Scale = 0;
            float iWidth = ((Width - 2 * XSpace) / XSlice) * 50; //将要画刻度的长度分段，并乘以50，以10为单位画刻度线。
            float fltSliceHeight = XSlice / 10; //刻度线的高度
            objGraphics.TranslateTransform(fltX1, fltY1); //平移图像(原点)
            objGraphics.RotateTransform(XRotateAngle, MatrixOrder.Prepend); //旋转图像
            objGraphics.DrawString(Keys[0].ToString(), new Font("宋体", FontSize), new SolidBrush(SliceTextColor), 0, 0);
            objGraphics.ResetTransform(); //重置图像
            for (int i = 0; i <= iWidth; i += 10) //以10为单位
            {
                Scale = i * XSlice / 50;//即(i / 10) * (XSlice / 5)，将每个刻度分五部分画，但因为i以10为单位，得除以10
                if (iCount == 5)
                {
                    objGraphics.DrawLine(new Pen(new SolidBrush(AxisColor)), fltX1 + Scale, fltY1 + fltSliceHeight * 1.5f, fltX2 + Scale, fltY2 - fltSliceHeight * 1.5f);
                    //画网格虚线
                    Pen penDashed = new Pen(new SolidBrush(AxisColor));
                    penDashed.DashStyle = DashStyle.Dash;
                    objGraphics.DrawLine(penDashed, fltX1 + Scale, fltY1, fltX2 + Scale, YSpace - YSlice / 2);
                    //这里显示X轴刻度
                    if (iSliceCount <= Keys.Length - 1)
                    {
                        objGraphics.TranslateTransform(fltX1 + Scale, fltY1);
                        objGraphics.RotateTransform(XRotateAngle, MatrixOrder.Prepend);
                        objGraphics.DrawString(Keys[iSliceCount].ToString(), new Font("宋体", FontSize), new SolidBrush(SliceTextColor), 0, 0);
                        objGraphics.ResetTransform();
                    }
                    else
                    {
                        //超过范围，不画任何刻度文字
                    }
                    iCount = 0;
                    iSliceCount++;
                    if (fltX1 + Scale > Width - XSpace)
                    {
                        break;
                    }
                }
                else
                {
                    objGraphics.DrawLine(new Pen(new SolidBrush(SliceColor)), fltX1 + Scale, fltY1 + fltSliceHeight, fltX2 + Scale, fltY2 - fltSliceHeight);
                }
                iCount++;
            }
        }
        /// <summary>
        /// 初始化Y轴上的刻度和文字
        /// </summary>
        /// <param name="objGraphics"></param>
        private void SetYAxis(ref Graphics objGraphics)
        {
            float fltX1 = XSpace;
            float fltY1 = Height - YSpace;
            float fltX2 = XSpace;
            float fltY2 = Height - YSpace;
            int iCount = 0;
            float Scale = 0;
            int iSliceCount = 1;
            float iHeight = ((Height - 2 * YSpace) / YSlice) * 50; //将要画刻度的长度分段，并乘以50，以10为单位画刻度线。
            float fltSliceWidth = YSlice / 10; //刻度线的宽度
            string strSliceText = string.Empty;
            objGraphics.TranslateTransform(XSpace - intFontSpace * YSliceBegin.ToString().Length, Height - YSpace); //平移图像(原点)
            objGraphics.RotateTransform(YRotateAngle, MatrixOrder.Prepend); //旋转图像
            objGraphics.DrawString(YSliceBegin.ToString(), new Font("宋体", FontSize), new SolidBrush(SliceTextColor), 0, 0);
            objGraphics.ResetTransform(); //重置图像
            for (int i = 0; i < iHeight; i += 10)
            {
                Scale = i * YSlice / 50; //即(i / 10) * (YSlice / 5)，将每个刻度分五部分画，但因为i以10为单位，得除以10
                if (iCount == 5)
                {
                    objGraphics.DrawLine(new Pen(new SolidBrush(AxisColor)), fltX1 - fltSliceWidth * 1.5f, fltY1 - Scale, fltX2 + fltSliceWidth * 1.5f, fltY2 - Scale);
                    //画网格虚线
                    Pen penDashed = new Pen(new SolidBrush(AxisColor));
                    penDashed.DashStyle = DashStyle.Dash;
                    objGraphics.DrawLine(penDashed, XSpace, fltY1 - Scale, Width - XSpace + XSlice / 2, fltY2 - Scale);
                    //这里显示Y轴刻度
                    strSliceText = System.Convert.ToString(YSliceValue * iSliceCount + YSliceBegin);
                    objGraphics.TranslateTransform(XSpace - intFontSize * strSliceText.Length, fltY1 - Scale); //平移图像(原点)
                    objGraphics.RotateTransform(YRotateAngle, MatrixOrder.Prepend); //旋转图像
                    objGraphics.DrawString(strSliceText, new Font("宋体", FontSize), new SolidBrush(SliceTextColor), 0, 0);
                    objGraphics.ResetTransform(); //重置图像
                    iCount = 0;
                    iSliceCount++;
                }
                else
                {
                    objGraphics.DrawLine(new Pen(new SolidBrush(SliceColor)), fltX1 - fltSliceWidth, fltY1 - Scale, fltX2 + fltSliceWidth, fltY2 - Scale);
                }
                iCount++;
            }
        }
        /// <summary>
        /// 画曲线
        /// </summary>
        /// <param name="objGraphics"></param>
        private void DrawContent(ref Graphics objGraphics, float[] fltCurrentValues, Color clrCurrentColor)
        {
            Pen CurvePen = new Pen(clrCurrentColor, CurveSize);
            PointF[] CurvePointF = new PointF[Keys.Length];
            float keys = 0;
            float values = 0;
            for (int i = 0; i < Keys.Length; i++)
            {
                keys = XSlice * i + XSpace;
                values = (Height - YSpace) + YSliceBegin - YSlice * (fltCurrentValues[i] / YSliceValue);
                CurvePointF[i] = new PointF(keys, values);
            }
            objGraphics.DrawCurve(CurvePen, CurvePointF, Tension);
        }
        /// <summary>
        /// 初始化标题
        /// </summary>
        /// <param name="objGraphics"></param>
        private void CreateTitle(ref Graphics objGraphics)
        {
            objGraphics.DrawString(Title, new Font("宋体", FontSize), new SolidBrush(TextColor), new Point((int)(Width - XSpace) - intFontSize * Title.Length, (int)(YSpace - YSlice / 2 - intFontSpace)));
        }
    }

    /// <summary>
    /// 柱状图
    /// </summary>
    public class Histogram
    {
        //int[] a = new int[] { 30, 20, 50, 40, 40, 78, 45, 98, 87, 47, 46, 98 };
        //  int w = 400;
        //  int h = 450;
        //  Bitmap graph = new Bitmap(w, h);
        //  Graphics g = Graphics.FromImage(graph);
        //  g.Clear(Color.White);
        //  g.DrawRectangle(Pens.AliceBlue, 0, 0, 399, 399);
        //  string title = "2009销售情况统计表";
        //  Font f = new Font("黑体", 16);
        //  g.DrawString(title, f, Brushes.Blue, (w / 2 - g.MeasureString(title, f).Width / 2), 2);
        //  float v_width = w;
        //  float v_height = w - 2 - g.MeasureString(title, f).Height - 10;
        //  float p_width = w / 25;
        //  float p_heigth = v_height / 150;
        //  float x = 0;
        //  float y = 0;
        //  double k = 0;
        //  Font f9 = new Font("宋体", 9);
        //  for (int i = 0; i < 12; i++)
        //  {
        //      x = (i * 2 + 1) * p_width;
        //      y = w - p_heigth * a[i];
        //      g.FillRectangle(Brushes.Black, x, y, p_width, a[i] * p_heigth);
        //      k = i + 1;
        //      g.DrawString(k.ToString() + "月", f9, Brushes.Black, x, w + 2);

        //      g.DrawString(a[i].ToString(), f9, Brushes.Black, x - 4, y - 2 - g.MeasureString(a[i].ToString(), f9).Width / 2 - 2);
        //  }
        //  MemoryStream stream = new MemoryStream();
        //  graph.Save(stream, System.Drawing.Imaging.ImageFormat.Gif);
        //  System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
        //  //pictureBox1.Image = img;
        //  //graph = Utility.ChartHelper.GetPieGraph("Compex各组别不合格率统计", 600, 500, 100, 30, dt);
        //  graph.Save(stream, ImageFormat.Jpeg);
        //  //图片输出
        //  Response.Clear();
        //  Response.ContentType = "image/jpeg";
        //  Response.BinaryWrite(stream.ToArray());
        //  stream.Close();
    }

    #region ##

    /// <summary>
    /// 封装OWC做统计图
    /// 例：
    /// OWCChart owc = new OWCChart("测试", "123", 1000, 400);
    /// owc.DataSource = BasicAccess.SqlHelper.ExecuteDataset("server=192.168.1.45;uid=sa;pwd=123456;database=PeopleDataCenter;Max Pool Size=500; Min Pool Size=1", CommandType.Text, "select top 20 workOrgan,count(*) from work where workOrgan is not null and workOrgan!='' group by workOrgan order by count(*) desc").Tables[0];
    /// owc.PhaysicalImagePath = "D:\\web"; owc.CreateColumn("x", "y", true, false);
    /// </summary>
    //public class OWCChart
    //{
    //    #region 属性

    //    private String _phaysicalimagepath;
    //    private String _title;
    //    private String _seriesname;
    //    private Int32 _picwidth;
    //    private Int32 _pichight;
    //    private data _datasource;
    //    private String _strdatasource;
    //    private String strCategory;
    //    private String strValue;

    //    /// <summary>
    //    /// 图片存放路径
    //    /// </summary>
    //    public string PhaysicalImagePath
    //    {
    //        set { _phaysicalimagepath = value; }
    //        get { return _phaysicalimagepath; }
    //    }

    //    public string Title
    //    {
    //        set { _title = value; }
    //        get { return _title; }
    //    }

    //    public string SeriesName
    //    {
    //        set { _seriesname = value; }
    //        get { return _seriesname; }
    //    }

    //    public Int32 PicWidth
    //    {
    //        set { _picwidth = value; }
    //        get { return _picwidth; }
    //    }

    //    public Int32 PicHight
    //    {
    //        set { _pichight = value; }
    //        get { return _pichight; }
    //    }

    //    /// <summary>
    //    /// 传data类型
    //    /// </summary>
    //    public data DataSource
    //    {
    //        set
    //        {
    //            _datasource = value;
    //            strCategory = GetColumnsStr(_datasource);
    //            strValue = GetValueStr(_datasource);
    //        }
    //        get { return _datasource; }
    //    }

    //    /// <summary>
    //    /// 传字符串，分隔用分号(;)
    //    /// </summary>
    //    public string strDataSource
    //    {
    //        set
    //        {
    //            _strdatasource = value;
    //            strCategory = GetColumnsStr(_strdatasource);
    //            strValue = GetValueStr(_strdatasource);
    //        }
    //        get { return _strdatasource; }
    //    }

    //    private String GetColumnsStr(data dt)
    //    {
    //        StringBuilder strList = new StringBuilder();
    //        foreach (DataRow r in dt.Rows)
    //        {
    //            strList.Append(r[0].ToString() + '\t');
    //        }
    //        return strList.ToString();
    //    }

    //    private String GetColumnsStr(string coldt)
    //    {
    //        return coldt == "" ? "" : coldt.Substring(0, coldt.IndexOf(";"));
    //    }

    //    private String GetValueStr(data dt)
    //    {
    //        StringBuilder strList = new StringBuilder();
    //        foreach (DataRow r in dt.Rows)
    //        {
    //            strList.Append(r[1].ToString() + '\t');
    //        }
    //        return strList.ToString();
    //    }

    //    private String GetValueStr(string rowdt)
    //    {
    //        return rowdt == "" ? "" : rowdt.Substring(rowdt.LastIndexOf(";") + 1);
    //    }

    //    #endregion
    //    #region 构造函数

    //    /// <summary>
    //    /// 0
    //    /// </summary>
    //    public OWCChart()
    //    {
    //        //
    //    }

    //    /// <summary>
    //    /// 1
    //    /// </summary>
    //    /// <param name="PhaysicalImagePath"></param>
    //    /// <param name="Title"></param>
    //    /// <param name="SeriesName"></param>
    //    /// <param name="PicWidth"></param>
    //    /// <param name="PicHight"></param>
    //    public OWCChart(string PhaysicalImagePath, string Title, string SeriesName, int PicWidth, int PicHight)
    //    {
    //        _phaysicalimagepath = PhaysicalImagePath;
    //        _title = Title;
    //        _seriesname = SeriesName;
    //        _pichight = PicHight;
    //        _picwidth = PicWidth;
    //    }

    //    /// <summary>
    //    /// 2
    //    /// </summary>
    //    /// <param name="Title"></param>
    //    /// <param name="SeriesName"></param>
    //    /// <param name="PicWidth"></param>
    //    /// <param name="PicHight"></param>
    //    public OWCChart(string Title, string SeriesName, int PicWidth, int PicHight)
    //    {
    //        _title = Title;
    //        _seriesname = SeriesName;
    //        _pichight = PicHight;
    //        _picwidth = PicWidth;
    //    }

    //    #endregion
    //    #region 柱形图

    //    /// <summary>
    //    /// 柱形图
    //    /// </summary>
    //    /// <param name="Xname">X轴描述</param>
    //    /// <param name="Yname">Y轴描述</param>
    //    /// <param name="IfExportToFile">若把图像输出到文件夹则为true，否则为false</param>
    //    /// <returns>若把图像输出到文件夹返回生成的图像名称，否则返回Bitmap类型</returns>
    //    public Object CreateColumn(string Xname, string Yname, bool IfExportToFile, bool If3D)
    //    {
    //        OWC11.ChartSpace objCSpace = new OWC11.ChartSpaceClass();//创建ChartSpace对象来放置图表   
    //        OWC11.ChChart objChart = objCSpace.Charts.Add(0);//在ChartSpace对象中添加图表，Add方法返回chart对象

    //        //指定图表的类型。类型由OWC11.ChartChartTypeEnum枚举值得到
    //        if (If3D == true)
    //            objChart.Type = OWC11.ChartChartTypeEnum.chChartTypeColumnClustered3D;
    //        else
    //            objChart.Type = OWC11.ChartChartTypeEnum.chChartTypeColumnClustered;

    //        //指定图表是否需要图例
    //        objChart.HasLegend = true;

    //        //标题
    //        objChart.HasTitle = true;
    //        objChart.Title.Caption = _title;
    //        objChart.Title.Font.Bold = true;
    //        //          objChart.Title.Font.Color="blue";        
    //        #region 样式设置

    //        //旋转
    //        //            objChart.Rotation  = 145;//表示指定三维图表的旋转角度
    //        //            objChart.Inclination = 10;//表示指定三维图表的视图斜率。有效范围为 -90 到 90
    //        //
    //        //            //背景颜色
    //        //            objChart.PlotArea.Interior.Color = "red";
    //        //
    //        //            //底座颜色
    //        //            objChart.PlotArea.Floor.Interior.Color = "green";
    //        //            objChart.Overlap = 50;//单个类别中标志之间的重叠量

    //        #endregion

    //        //x,y轴的图示说明
    //        objChart.Axes[0].HasTitle = true;
    //        objChart.Axes[0].Title.Caption = "X ： " + Xname + "";
    //        objChart.Axes[1].HasTitle = true;
    //        objChart.Axes[1].Title.Caption = "Y ： " + Yname + "";

    //        //添加一个series
    //        OWC11.ChSeries ThisChSeries = objChart.SeriesCollection.Add(0);

    //        //给定series的名字
    //        ThisChSeries.SetData(OWC11.ChartDimensionsEnum.chDimSeriesNames,
    //            OWC11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), SeriesName);
    //        //给定分类
    //        ThisChSeries.SetData(OWC11.ChartDimensionsEnum.chDimCategories,
    //            OWC11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strCategory);
    //        //给定值
    //        ThisChSeries.SetData(OWC11.ChartDimensionsEnum.chDimValues,
    //            OWC11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strValue);

    //        OWC11.ChDataLabels dl = objChart.SeriesCollection[0].DataLabelsCollection.Add();
    //        dl.HasValue = true;
    //        //          dl.Position=OWC11.ChartDataLabelPositionEnum.chLabelPositionOutsideEnd;

    //        //            string filename=DateTime.Now.ToString("yyyyMMddHHmmssff")+".gif";

    //        if (IfExportToFile == true)
    //        {
    //            string filename = "temp.gif";
    //            string strAbsolutePath = _phaysicalimagepath + "\\" + filename;
    //            objCSpace.ExportPicture(strAbsolutePath, "GIF", _picwidth, _pichight); //输出成GIF文件.

    //            return filename;
    //        }
    //        else
    //        {
    //            string tmp = "Tmp";
    //            objCSpace.ExportPicture(tmp, "GIF", _picwidth, _pichight);
    //            Bitmap bm = new Bitmap(tmp, true);

    //            return bm;
    //        }
    //    }

    //    #endregion
    //    #region 线性图

    //    /// <summary>
    //    /// 线性图
    //    /// </summary>
    //    /// <param name="Xname">X轴描述</param>
    //    /// <param name="Yname">Y轴描述</param>
    //    /// <param name="IfExportToFile">若把图像输出到文件夹则为true，否则为false</param>
    //    /// <returns>若把图像输出到文件夹返回生成的图像名称，否则返回Bitmap类型</returns>
    //    public Object CreateLine(string Xname, string Yname, bool IfExportToFile, bool If3D)
    //    {
    //        OWC11.ChartSpace objCSpace = new OWC11.ChartSpaceClass();//创建ChartSpace对象来放置图表   
    //        OWC11.ChChart objChart = objCSpace.Charts.Add(0);//在ChartSpace对象中添加图表，Add方法返回chart对象

    //        //指定图表的类型。类型由OWC11.ChartChartTypeEnum枚举值得到
    //        if (If3D == true)
    //            objChart.Type = OWC11.ChartChartTypeEnum.chChartTypeLine3D;
    //        else
    //            objChart.Type = OWC11.ChartChartTypeEnum.chChartTypeLine;

    //        //指定图表是否需要图例
    //        objChart.HasLegend = true;

    //        //标题
    //        objChart.HasTitle = true;
    //        objChart.Title.Caption = _title;
    //        objChart.Title.Font.Bold = true;
    //        //          objChart.Title.Font.Color="blue";        
    //        #region 样式设置

    //        //旋转
    //        //            objChart.Rotation  = 145;//表示指定三维图表的旋转角度
    //        //            objChart.Inclination = 10;//表示指定三维图表的视图斜率。有效范围为 -90 到 90
    //        //
    //        //            //背景颜色
    //        //            objChart.PlotArea.Interior.Color = "red";
    //        //
    //        //            //底座颜色
    //        //            objChart.PlotArea.Floor.Interior.Color = "green";
    //        //            objChart.Overlap = 50;//单个类别中标志之间的重叠量

    //        #endregion

    //        //x,y轴的图示说明
    //        objChart.Axes[0].HasTitle = true;
    //        objChart.Axes[0].Title.Caption = "X ： " + Xname + "";
    //        objChart.Axes[1].HasTitle = true;
    //        objChart.Axes[1].Title.Caption = "Y ： " + Yname + "";

    //        //添加一个series
    //        OWC11.ChSeries ThisChSeries = objChart.SeriesCollection.Add(0);

    //        //给定series的名字
    //        ThisChSeries.SetData(OWC11.ChartDimensionsEnum.chDimSeriesNames,
    //            OWC11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), SeriesName);
    //        //给定分类
    //        ThisChSeries.SetData(OWC11.ChartDimensionsEnum.chDimCategories,
    //            OWC11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strCategory);
    //        //给定值
    //        ThisChSeries.SetData(OWC11.ChartDimensionsEnum.chDimValues,
    //            OWC11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strValue);

    //        OWC11.ChDataLabels dl = objChart.SeriesCollection[0].DataLabelsCollection.Add();
    //        dl.HasValue = true;
    //        //          dl.Position=OWC11.ChartDataLabelPositionEnum.chLabelPositionOutsideEnd;

    //        //            string filename=DateTime.Now.ToString("yyyyMMddHHmmssff")+".gif";

    //        if (IfExportToFile == true)
    //        {
    //            string filename = "temp.gif";
    //            string strAbsolutePath = _phaysicalimagepath + "\\" + filename;
    //            objCSpace.ExportPicture(strAbsolutePath, "GIF", _picwidth, _pichight); //输出成GIF文件.

    //            return filename;
    //        }
    //        else
    //        {
    //            string tmp = "Tmp";
    //            objCSpace.ExportPicture(tmp, "GIF", _picwidth, _pichight);
    //            Bitmap bm = new Bitmap(tmp, true);

    //            return bm;
    //        }
    //    }

    //    #endregion
    //    #region 条形图(横向)

    //    /// <summary>
    //    /// 条形图(横向)
    //    /// </summary>
    //    /// <param name="Xname"></param>
    //    /// <param name="Yname"></param>
    //    /// <param name="IfExportToFile"></param>
    //    /// <returns></returns>
    //    public Object CreateBar(string Xname, string Yname, bool IfExportToFile, bool If3D)
    //    {
    //        OWC11.ChartSpace objCSpace = new OWC11.ChartSpaceClass();//创建ChartSpace对象来放置图表   
    //        OWC11.ChChart objChart = objCSpace.Charts.Add(0);//在ChartSpace对象中添加图表，Add方法返回chart对象

    //        //指定图表的类型。类型由OWC.ChartChartTypeEnum枚举值得到
    //        if (If3D == true)
    //            objChart.Type = OWC11.ChartChartTypeEnum.chChartTypeBarClustered3D;
    //        else
    //            objChart.Type = OWC11.ChartChartTypeEnum.chChartTypeBarClustered;

    //        //指定图表是否需要图例
    //        objChart.HasLegend = true;

    //        //标题
    //        objChart.HasTitle = true;
    //        objChart.Title.Caption = _title;
    //        objChart.Title.Font.Bold = true;
    //        //          objChart.Title.Font.Color="blue";        
    //        #region 样式设置

    //        //旋转
    //        //            objChart.Rotation  = 145;//表示指定三维图表的旋转角度
    //        //            objChart.Inclination = 10;//表示指定三维图表的视图斜率。有效范围为 -90 到 90

    //        //背景颜色
    //        //            objChart.PlotArea.Interior.Color = "red";

    //        //底座颜色
    //        //            objChart.PlotArea.Floor.Interior.Color = "green";
    //        //            objChart.Overlap = 50;//单个类别中标志之间的重叠量

    //        #endregion

    //        //x,y轴的图示说明
    //        objChart.Axes[0].HasTitle = true;
    //        objChart.Axes[0].Title.Caption = "X ： " + Xname + "";
    //        objChart.Axes[1].HasTitle = true;
    //        objChart.Axes[1].Title.Caption = "Y ： " + Yname + "";

    //        //添加一个series
    //        OWC11.ChSeries ThisChSeries = objChart.SeriesCollection.Add(0);

    //        //给定series的名字
    //        ThisChSeries.SetData(OWC11.ChartDimensionsEnum.chDimSeriesNames,
    //            OWC11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), SeriesName);
    //        //给定分类
    //        ThisChSeries.SetData(OWC11.ChartDimensionsEnum.chDimCategories,
    //            OWC11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strCategory);
    //        //给定值
    //        ThisChSeries.SetData(OWC11.ChartDimensionsEnum.chDimValues,
    //            OWC11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strValue);

    //        OWC11.ChDataLabels dl = objChart.SeriesCollection[0].DataLabelsCollection.Add();
    //        dl.HasValue = true;
    //        //          dl.Position=OWC11.ChartDataLabelPositionEnum.chLabelPositionOutsideEnd;    

    //        //            string filename=DateTime.Now.ToString("yyyyMMddHHmmssff")+".gif";

    //        if (IfExportToFile == true)
    //        {
    //            string filename = "temp.gif";
    //            string strAbsolutePath = _phaysicalimagepath + "\\" + filename;
    //            objCSpace.ExportPicture(strAbsolutePath, "GIF", _picwidth, _pichight); //输出成GIF文件.

    //            return filename;
    //        }
    //        else
    //        {
    //            string tmp = "Tmp";
    //            objCSpace.ExportPicture(tmp, "GIF", _picwidth, _pichight);
    //            Bitmap bm = new Bitmap(tmp, true);

    //            return bm;
    //        }
    //    }

    //    #endregion
    //    #region 饼图

    //    /// <summary>
    //    /// 饼图
    //    /// </summary>
    //    /// <param name="IfExportToFile"></param>
    //    /// <returns></returns>
    //    public Object CreatePie(bool IfExportToFile, bool If3D)
    //    {
    //        OWC11.ChartSpace objCSpace = new OWC11.ChartSpaceClass();//创建ChartSpace对象来放置图表   
    //        OWC11.ChChart objChart = objCSpace.Charts.Add(0);//在ChartSpace对象中添加图表，Add方法返回chart对象       

    //        //指定图表的类型
    //        if (If3D == true)
    //            objChart.Type = OWC11.ChartChartTypeEnum.chChartTypePie3D;
    //        else
    //            objChart.Type = OWC11.ChartChartTypeEnum.chChartTypePie;

    //        //指定图表是否需要图例
    //        objChart.HasLegend = true;

    //        //标题
    //        objChart.HasTitle = true;
    //        objChart.Title.Caption = _title;
    //        objChart.Title.Font.Bold = true;

    //        //添加一个series
    //        OWC11.ChSeries ThisChSeries = objChart.SeriesCollection.Add(0);

    //        //给定series的名字
    //        ThisChSeries.SetData(OWC11.ChartDimensionsEnum.chDimSeriesNames,
    //            OWC11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), SeriesName);
    //        //给定分类
    //        ThisChSeries.SetData(OWC11.ChartDimensionsEnum.chDimCategories,
    //            OWC11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strCategory);
    //        //给定值
    //        ThisChSeries.SetData(OWC11.ChartDimensionsEnum.chDimValues,
    //            OWC11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strValue);

    //        //表示系列或趋势线上的单个数据标志
    //        OWC11.ChDataLabels dl = objChart.SeriesCollection[0].DataLabelsCollection.Add();
    //        dl.HasValue = true;
    //        dl.HasPercentage = true;
    //        //图表绘图区的图例放置在右侧。
    //        //          dl.Position=OWC11.ChartDataLabelPositionEnum.chLabelPositionRight;

    //        //            string filename=DateTime.Now.Ticks.ToString()+".gif"; 

    //        if (IfExportToFile == true)
    //        {
    //            string filename = "temp.gif";
    //            string strAbsolutePath = _phaysicalimagepath + "\\" + filename;
    //            objCSpace.ExportPicture(strAbsolutePath, "GIF", _picwidth, _pichight); //输出成GIF文件.

    //            return filename;
    //        }
    //        else
    //        {
    //            string tmp = "Tmp";
    //            objCSpace.ExportPicture(tmp, "GIF", _picwidth, _pichight);
    //            Bitmap bm = new Bitmap(tmp, true);

    //            return bm;
    //        }
    //    }

    //    #endregion
    //}
    #endregion
}

